﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using DevExpress.XtraEditors;

namespace MDIDemo.Modules
{
    public partial class NhapKho : DevExpress.XtraEditors.XtraForm
    {
        String sErr = "";
        DataRow _row = null;
        String IDKH = "";
        bool supplier = false;
        int idThem = 83;
        int idXoa = 85;
        void SetPermission()
        {
            if (this.Parent.Parent is frmMain)
            {
                frmMain main = (frmMain)this.Parent.Parent;
                btnThem.Visible = frmMain.IsPermis(idThem, main.CurrentPermis.PERMISSION);
                //btnSua.Visible = frmMain.IsPermis(idSua, main.CurrentPermis.PERMISSION);
                btnXoa.Visible = frmMain.IsPermis(idXoa, main.CurrentPermis.PERMISSION);
                btnLuu.Visible = frmMain.IsPermis(idThem, main.CurrentPermis.PERMISSION);
            }
        }

        public NhapKho()
        {
            InitializeComponent();
        }

        private void panelControl4_Paint(object sender, PaintEventArgs e)
        {

        }

        private void simpleButton2_Click(object sender, EventArgs e)
        {
            Windows.frmViewKhachHang kh = new Windows.frmViewKhachHang();
            if (kh.ShowDialog(this) == DialogResult.OK)
            {
                DTO.CUSTINFOInfo inf = new DTO.CUSTINFOInfo(kh.ReturnRow);
                txtDonViBH.Text = inf.TENGD;
                txtDiaChi.Text = inf.DIACHI;
                txtDienThoai.Text = inf.DIENTHOAI;
                //    txtMST.Text = inf.MSTHUE;
                //     txtHanMuc.EditValue = inf.HMDUNO;
                IDKH = inf.CUSTID;
                supplier = inf.NHACUNGCAP;
                txtDienThoai.Focus();
                //    txtDangNo.EditValue = TinhCongNo(inf.CUSTID);
                //      txtCT.Text =
            }
        }

        protected void LoadDSBan()
        {

            gridDSBan.ResetText();
            BUS.NXHANGControl ctr = new BUS.NXHANGControl();

            DataTable dt = ctr.GetByAllByCT(txtCT.Text == "" ? "-1" : txtCT.Text, (DateTime)txtNgay.EditValue, null, ref sErr);
            gridDSBan.DataSource = dt;
        }

        private void NhapKho_Load(object sender, EventArgs e)
        {
            LoadHangHoa();
            RefresForm("");
            EnabledForm(false);
            SetPermission();
        }

        private void RefresForm(string p)
        {
            txtDonViBH.Text = p;
            txtDienThoai.Text = p;
            txtDiaChi.Text = p;
            //     txtMST.Text = p;
            txtCT.Text = p;
            txtNgay.EditValue = frmMain.__ngayMoSo;
            txtTT.Text = "Normal";
            IDKH = "";
            //txtMaHang.Text = p;
            //txtTenHang.Text = p;
            //txtQuyCach.Text = p;
            //txtDonViTinh.Text = p;
            txtSoLuong.EditValue = p;
            txtDonGia.EditValue = p;
            txtTongTien.EditValue = p;
            txtThanhToan.EditValue = p;
            txtConNo.EditValue = p;
            txtTongCong.EditValue = p;
            lbNote.Text = p;

            //rgGia.SelectedIndex = 0;
            //cbPhiVanChuyen.Checked = false;
            //      cbDatCoc.Checked = false;
            //cbChietKhau.Checked = false;
            //txtTienDatTruoc.EditValue = 0;
            //txtTienThieu.EditValue = 0;
            //txtHanMuc.EditValue = 0;
            //txtDangNo.EditValue = 0;

            //txtTongcong.EditValue = 0;
            //txtTienDatTruoc.EditValue = 0;
            //txtTienThieu.EditValue = 0;
            //txtTienHang.EditValue = 0;


            LoadDSBan();
        }

        private void EnabledForm(bool p)
        {
            //txtDonViBH.Properties.ReadOnly = !p;
            txtDienThoai.Properties.ReadOnly = !p;
            //txtDiaChi.Properties.ReadOnly = !p;

            //txtCT.Properties.ReadOnly = true;
            //txtNgay.Properties.ReadOnly = true;
            //txtTT.Properties.ReadOnly = true;
            //txtTongCong.Properties.ReadOnly = true;
            //txtConNo.Properties.ReadOnly = true;


            txtSoLuong.Properties.ReadOnly = !p;
            txtDonGia.Properties.ReadOnly = !p;
            //txtTongTien.Properties.ReadOnly = !p;
            txtThanhToan.Properties.ReadOnly = !p;
            //   txtConNo.Properties.ReadOnly = !p;
            //     txtTongCong.Properties.ReadOnly = !p;
            //       rgGia.Properties.ReadOnly = !p;
            //      cbPhiVanChuyen.Properties.ReadOnly = !p;
            //    cbDatCoc.Properties.ReadOnly = !p;
            //      cbChietKhau.Properties.ReadOnly = !p;
            //      txtTienDatTruoc.Properties.ReadOnly = !p;
            //      //       txtTienThieu.Properties.ReadOnly = !p;

            if (frmMain.__khoaSo)
            {
                btnXoa.Enabled = btnThem.Enabled = false;
            }
            else
            {
                btnXoa.Enabled = btnThem.Enabled = !p;
            }

            btnLuu.Enabled = p;
            btnBoQua.Enabled = p;
            btnTimKiem.Enabled = !p;
            btnIn.Enabled = !p;
            btnDong.Enabled = !p;

            btnDoiDonVi.Enabled = p;
            btnTimKH.Enabled = p;
            btThem.Enabled = p;
            //        btXoa.Enabled = p;
        }

        protected void LoadHangHoa()
        {
            BUS.NHOMHANGControl ctr = new BUS.NHOMHANGControl();
            tlHangHoa.DataSource = ctr.GetTreeList("", ref sErr);
            tlHangHoa.ExpandAll();
        }

        private void tlHangHoa_FocusedNodeChanged(object sender, DevExpress.XtraTreeList.FocusedNodeChangedEventArgs e)
        {
            if (e.Node != null)
            {
                BUS.LOAIHANGControl ctr = new BUS.LOAIHANGControl();
                gridSanPham.DataSource = ctr.GetTonKho(e.Node.GetValue("ParentID").ToString(), e.Node.GetValue("ID").ToString(), -1, null, ref sErr);
            }
        }

        private void gvSanPham_FocusedRowChanged(object sender, DevExpress.XtraGrid.Views.Base.FocusedRowChangedEventArgs e)
        {

        }

        private void btnThem_Click(object sender, EventArgs e)
        {
            EnabledForm(true);
            RefresForm("");
            BUS.GIAODICHControl ctr = new BUS.GIAODICHControl();
            //DataTable dt = ctr.GetALLByCT(null, null, frmMain.__ngayMoSo, ref sErr);
            //int i = 1;
            //txtCT.Text = (dt.Rows.Count + i).ToString("00000");

            //while (ctr.IsExist(txtCT.Text, null, frmMain.__ngayMoSo))
            //{
            //    txtCT.Text = (dt.Rows.Count + i).ToString("00000");
            //    i++;
            //}
            BUS.CommonControl cmm = new BUS.CommonControl();
            txtCT.Text = cmm.GetSoCTNextNo(frmMain.__ngayMoSo.ToString("yyyy-MM-dd"));

            SetMatHangInfo();
            btnTimKH.Focus();
        }

        private void gvDSBan_RowClick(object sender, DevExpress.XtraGrid.Views.Grid.RowClickEventArgs e)
        {
            if (e.RowHandle >= 0)
            {
                DTO.NXHANGInfo inf = new DTO.NXHANGInfo(((DataRowView)gvDSBan.GetRow(e.RowHandle)).Row);

                //txtTenHang.Text = ((DataRowView)gvDSBan.GetRow(e.RowHandle)).Row["TENHANG"].ToString();
                //txtMaHang.Text = inf.LOAIHANG;
                //txtQuyCach.Text = inf.QUYCACH;
                //txtDonViTinh.Text = inf.DVTINH;
                txtSoLuong.EditValue = inf.SOLUONG;
                txtDonGia.EditValue = inf.GIABAN;
                txtTongTien.EditValue = inf.SOTIEN;
            }
        }

        private void btnDong_Click(object sender, EventArgs e)
        {
            Close();
        }

        private void simpleButton1_Click(object sender, EventArgs e)
        {
            Windows.frmViewQuyDoiDonVi kh = new Windows.frmViewQuyDoiDonVi();
            if (kh.ShowDialog(this) == DialogResult.OK)
            {
                txtSoLuong.EditValue = kh.Value;
                txtDonGia.Focus();
            }
        }

        private void txtDonGia_EditValueChanged(object sender, EventArgs e)
        {

        }

        private void btThem_Click(object sender, EventArgs e)
        {
            if (_row != null)
            {

                if (txtSoLuong.Text != "0" && txtDonGia.Text != "0" && txtTongTien.Text != "0")
                {
                    DataTable dt = (DataTable)gridDSBan.DataSource;
                    DataRow[] arr = dt.Select("LOAIHANG ='" + _row["MAHANG"].ToString() + "'");
                    if (arr.Length > 0)
                    {
                        dt.Rows.Remove(arr[0]);
                    }
                    DTO.TONKHOInfo tonkhoinf = new DTO.TONKHOInfo(_row);
                    DTO.NXHANGInfo inf = new DTO.NXHANGInfo();
                    inf.LOAIHANG = tonkhoinf.MAHANG;
                    inf.SOCT = txtCT.Text;
                    inf.LINE = dt.Rows.Count + 1;
                    inf.LOAICT = "NH001";
                    inf.NGAYCT = (DateTime)txtNgay.EditValue;
                    inf.QUYCACH = _row["QUYCACH"].ToString();
                    inf.DVTINH = _row["DVTINH"].ToString();
                    inf.SOLUONG = Convert.ToDouble(txtSoLuong.EditValue);
                    //     inf.GIAVON = tonkhoinf.GIAVON;
                    inf.GIABAN = Convert.ToDouble(txtDonGia.EditValue);
                    inf.SOTIEN = Convert.ToDouble(txtTongTien.EditValue);
                    inf.TINHTRANG = txtTT.Text;
                    inf.XUATKHO = true;


                    DataRow row = inf.ToDataRow(dt);
                    row["TENHANG"] = _row["TENHANG"].ToString();
                    dt.Rows.Add(row);


                    gridDSBan.DataSource = dt;
                    TinhTongCong();
                }
                else
                {
                    XtraMessageBox.Show("Bạn chưa nhập giá trị");
                }
            }
        }
        protected void TinhTongCong()
        {
            Double kq = 0;

            DataTable dt = (DataTable)gridDSBan.DataSource;
            foreach (DataRow row in dt.Rows)
            {
                kq += Convert.ToDouble(row[DTO.NXHANGInfo.Field.SOTIEN.ToString()].ToString());
            }
            txtTongCong.EditValue = kq;
            txtConNo.EditValue = kq - Convert.ToDouble(txtThanhToan.EditValue == "" ? "0" : txtThanhToan.EditValue);

        }

        private void txtThanhToan_EditValueChanged(object sender, EventArgs e)
        {
            if (txtThanhToan.Text != "")
            {
                txtConNo.EditValue = Convert.ToDouble(txtTongCong.EditValue) - Convert.ToDouble(txtThanhToan.EditValue);
            }
        }

        private void btXoa_Click(object sender, EventArgs e)
        {
            int[] s = gvDSBan.GetSelectedRows();
            if (s.Length > 0)
            {
                gvDSBan.DeleteSelectedRows();
                TinhTongCong();
            }
        }

        protected String SaveHeader()
        {
            BUS.GIAODICHControl ctr = new BUS.GIAODICHControl();
            //DataTable dt = ctr.GetALLByCT(null, null, frmMain.__ngayMoSo, ref sErr);
            //int i = 1;
            //txtCT.Text = (dt.Rows.Count + i).ToString("00000");

            //while (ctr.IsExist(txtCT.Text, null, frmMain.__ngayMoSo))
            //{
            //    txtCT.Text = (dt.Rows.Count + i).ToString("00000");
            //    i++;
            //}
            BUS.CommonControl cmm = new BUS.CommonControl();
            txtCT.Text = cmm.GetSoCTNextNo(frmMain.__ngayMoSo.ToString("yyyy-MM-dd"));

            DTO.GIAODICHInfo inf = new DTO.GIAODICHInfo();
            inf.SOCT = txtCT.Text;

            inf.NGAYCT = (DateTime)txtNgay.EditValue;
            inf.MAKH = IDKH;
            //    inf.TIENHANG = Convert.ToDouble(txtTienHang.EditValue);
            //     inf.PHIVC = Convert.ToDouble(txtPhiVanChuyen.EditValue);
            //     inf.CHIETKHAU = Convert.ToDouble(txtChieutkhau.EditValue);
            inf.TONGTIEN = Convert.ToDouble(txtTongCong.EditValue);

            inf.CONGNO = Convert.ToDouble(txtConNo.EditValue);
            inf.TIENMAT = Convert.ToDouble(txtThanhToan.EditValue == "" ? "0" : txtThanhToan.EditValue);
            inf.LOAITIEN = "VND";
            inf.DIACHIKH = txtDiaChi.Text;
            inf.DIENTHOAI = txtDienThoai.Text;
            if (supplier)
            {
                inf.LOAICT = "NH001";
                inf.NOIDUNG = "Mua hàng nhập kho";
            }
            else
            {
                inf.LOAICT = "NH001";
                inf.NOIDUNG = "Mua lại hàng của khách hàng";
            }
            inf.TINHTRANG = txtTT.Text;
            inf.INHD = true;
            inf.CREATEBY = frmMain.__userID;
            inf.MODIFIEDBY = frmMain.__userID;
            inf.CREATEDATE = frmMain.__ngayMoSo;
            inf.MODIFIEDDATE = frmMain.__ngayMoSo;

            ctr.Add(inf, ref sErr);

            return sErr;
        }


        protected String SaveDetail()
        {
            BUS.LOAIHANGControl lhctr = new BUS.LOAIHANGControl();
            BUS.TONKHOControl tonkhoctr = new BUS.TONKHOControl();
            BUS.NXHANGControl ctr = new BUS.NXHANGControl();
            DataTable dt = (DataTable)gridDSBan.DataSource;
            int line = 1;
            string err = "";
            foreach (DataRow row in dt.Rows)
            {
                DTO.NXHANGInfo inf = new DTO.NXHANGInfo(row);

                inf.SOCT = txtCT.Text;
                inf.LOCATION = "0001";
                inf.LINE = line;
                inf.GIAVON = inf.GIABAN;
                ctr.Add(inf, ref err);
                sErr += err;
                if (sErr == "")
                {
                    DTO.LOAIHANGInfo lhinf = lhctr.Get(inf.LOAIHANG, ref sErr);
                    DTO.TONKHOInfo tkinf = new DTO.TONKHOInfo();
                    tkinf = tonkhoctr.Get(lhinf.NHOMHANG, lhinf.MAHANG, ref sErr);
                    tkinf.SOLUONG = tkinf.SOLUONG + inf.SOLUONG;
                    tkinf.SOTIEN = tkinf.SOTIEN + inf.SOTIEN;
                    tkinf.GIAVON = tkinf.SOLUONG == 0 ? 0 : Math.Round(tkinf.SOTIEN / tkinf.SOLUONG, 3);

                    sErr += tonkhoctr.Update(tkinf);
                }
                line++;
            }

            return sErr;
        }

        protected String SaveCongNo()
        {
            BUS.CONGNOControl ctr = new BUS.CONGNOControl();
            DTO.CONGNOInfo inf = new DTO.CONGNOInfo();

            inf.SOCT = txtCT.Text;
            inf.NGAYCT = (DateTime)txtNgay.EditValue;
            inf.DIACHIKH = txtDiaChi.Text;
            inf.DIENTHOAI = txtDienThoai.Text;

            inf.PHAITHU = false;
            inf.D_C = "";
            inf.SOTIEN = Convert.ToDouble(txtTongCong.EditValue) * (-1);
            if (supplier)
            {
                inf.NOIDUNG = "Mua hàng nhập kho";
                inf.MAKH = IDKH;
                inf.SOCTTT = txtCT.Text;
                inf.SOCTTT = "NH";
            }
            else
            {
                inf.NOIDUNG = "Mua lại hàng của khách hàng";
                inf.MAKH = IDKH;
                inf.SOCTTT = txtCT.Text;
                inf.SOCTTT = "BH";
            }
            inf.CREATEBY = frmMain.__userID;
            inf.MODIFIEDBY = frmMain.__userID;
            inf.CREATEDATE = frmMain.__ngayMoSo;
            inf.MODIFIEDDATE = frmMain.__ngayMoSo;

            ctr.Add(inf, ref sErr);

            // tra truoc
            if (Convert.ToInt32(txtThanhToan.EditValue == "" ? "0" : txtThanhToan.EditValue) > 0)
            {
                inf.PHAITHU = true;

                inf.SOTIEN = Convert.ToDouble(txtThanhToan.EditValue);
                if (supplier)
                {
                    inf.D_C = "N";
                    inf.NOIDUNG = "Trả tiền nhập kho";
                }
                else
                {
                    inf.D_C = "C";
                    inf.NOIDUNG = "Trả tiền mua lại của khách hàng";
                }
                ctr.Add(inf, ref sErr);
            }



            return sErr;
        }

        private void btnLuu_Click(object sender, EventArgs e)
        {
            sErr = "";
            if (IDKH == "")
            {
                XtraMessageBox.Show("Vui lòng nhập thêm thông tin khách hàng", "Thông báo");
                return;
            }
            if (gvDSBan.RowCount == 0)
            {
                XtraMessageBox.Show("Vui lòng nhập thêm thông tin sản phẩm", "Thông báo");
                return;
            }
            sErr = SaveHeader();

            if (sErr == "")
            {
                sErr = SaveDetail();
                if (sErr == "")
                    sErr = SaveCongNo();

            }
            if (sErr != "")
            {
                XtraMessageBox.Show(sErr);
                btnXoa_Click(null, null);
            }
            else
            {
                XtraMessageBox.Show("Lưu thành công");
                //                RefresForm("");
                EnabledForm(false);
            }
        }

        private void btnBoQua_Click(object sender, EventArgs e)
        {
            RefresForm("");
            EnabledForm(false);
        }

        private void btnXoa_Click(object sender, EventArgs e)
        {
            sErr = "";
            if (XtraMessageBox.Show("Bạn có thực sự muốn xóa", "Thông báo", MessageBoxButtons.OKCancel) == DialogResult.OK)
            {
                sErr = DeleteHeader(txtCT.Text, (DateTime)txtNgay.EditValue);
                if (sErr == "")
                {
                    sErr = DeleteDetail(txtCT.Text, (DateTime)txtNgay.EditValue);
                    if (sErr == "")
                    {
                        sErr = DeleteCongNo(txtCT.Text, (DateTime)txtNgay.EditValue);
                    }
                }
                if (sErr != "")
                    XtraMessageBox.Show(sErr);
                else
                {
                    RefresForm("");
                    EnabledForm(false);
                }
            }
        }

        protected String DeleteHeader(String ct, DateTime ngay)
        {
            BUS.GIAODICHControl ctr = new BUS.GIAODICHControl();
            sErr = ctr.Delete(ct, "NH001", ngay);

            return sErr;
        }

        protected String DeleteDetail(String ct, DateTime ngay)
        {
            BUS.TONKHOControl tonkhoctr = new BUS.TONKHOControl();
            BUS.LOAIHANGControl lhctr = new BUS.LOAIHANGControl();
            BUS.NXHANGControl ctr = new BUS.NXHANGControl();
            DataTable dt = ctr.GetByAllByCT(ct, ngay, "NH001", ref sErr);

            foreach (DataRow row in dt.Rows)
            {
                DTO.NXHANGInfo inf = new DTO.NXHANGInfo(row);
                sErr += ctr.Delete(ct, inf.LINE, inf.LOAICT, inf.NGAYCT);
                if (sErr == "")
                {
                    DTO.LOAIHANGInfo lhinf = lhctr.Get(inf.LOAIHANG, ref sErr);
                    DTO.TONKHOInfo tkinf = new DTO.TONKHOInfo();
                    tkinf = tonkhoctr.Get(lhinf.NHOMHANG, lhinf.MAHANG, ref sErr);
                    tkinf.SOLUONG = tkinf.SOLUONG - inf.SOLUONG;
                    tkinf.SOTIEN = tkinf.SOTIEN - inf.SOTIEN;
                    tkinf.GIAVON = tkinf.SOLUONG == 0 ? 0 : Math.Round(tkinf.SOTIEN / tkinf.SOLUONG, 2);
                    sErr += tonkhoctr.Update(tkinf);
                }
            }

            return sErr;
        }

        protected String DeleteCongNo(String ct, DateTime ngay)
        {
            BUS.CONGNOControl ctr = new BUS.CONGNOControl();
            DataTable dt = ctr.GetALLByCT(ct, ngay, ref sErr);

            foreach (DataRow row in dt.Rows)
            {
                DTO.CONGNOInfo inf = new DTO.CONGNOInfo(row);
                sErr = ctr.Delete(inf.ID);
            }

            return sErr;
        }

        private void btnTimKiem_Click(object sender, EventArgs e)
        {
            Windows.frmViewGiaoDich gd = new Windows.frmViewGiaoDich();
            gd.LoaiCT = "NH001";
            if (gd.ShowDialog(this) == DialogResult.OK)
            {
                DTO.GIAODICHInfo inf = new DTO.GIAODICHInfo(gd.ReturnRow);

                txtCT.Text = inf.SOCT;
                txtNgay.EditValue = inf.NGAYCT;
                IDKH = inf.MAKH;
                BUS.CUSTINFOControl ctr = new BUS.CUSTINFOControl();
                DTO.CUSTINFOInfo infCus = ctr.Get(IDKH, ref sErr);
                txtDonViBH.Text = infCus.TENGD;
                //txtTienHang.EditValue = inf.TIENHANG;
                //txtPhiVanChuyen.EditValue = inf.PHIVC;
                //txtChieutkhau.EditValue = inf.CHIETKHAU;
                txtTongCong.EditValue = inf.TONGTIEN;
                txtConNo.EditValue = inf.CONGNO;
                txtThanhToan.EditValue = inf.TIENMAT;

                txtDiaChi.Text = inf.DIACHIKH;
                txtDienThoai.Text = inf.DIENTHOAI;
                txtTT.EditValue = inf.TINHTRANG;

                LoadDSBan();
                //btThem.Enabled = true;
                //btXoa.Enabled = true;

                //btnThem.Enabled = false;
                //EnabledForm(true);
            }
        }

        private void gvSanPham_RowClick(object sender, DevExpress.XtraGrid.Views.Grid.RowClickEventArgs e)
        {
            if (e.RowHandle >= 0)
            {
                if (btnThem.Enabled == false)
                {
                    SetMatHangInfo();

                    txtSoLuong.Focus();
                }
            }
        }

        private void SetMatHangInfo()
        {
            _row = ((DataRowView)gvSanPham.GetRow(gvSanPham.FocusedRowHandle)).Row;

            //txtMaHang.Text = _row["MAHANG"].ToString();
            //txtTenHang.Text = _row["TENHANG"].ToString();
            //txtQuyCach.Text = _row["QUYCACH"].ToString();
            //txtDonViTinh.Text = _row["DVTINH"].ToString();

            txtSoLuong.EditValue = 0;
            txtDonGia.EditValue = 0;
            txtTongTien.EditValue = 0;

            lbNote.Text = "Đang thực hiện nhập kho mặt hàng " + _row["MAHANG"].ToString() + "-" + _row["TENHANG"].ToString();
        }

        private void txtTongTien_EditValueChanged(object sender, EventArgs e)
        {

        }

        private void btnIn_Click(object sender, EventArgs e)
        {

        }

        private void NhapKho_KeyUp(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == Keys.Escape)
            {
                if (btnBoQua.Enabled)
                    btnBoQua_Click(null, null);

            }
            else if (e.KeyCode == Keys.F7)
            {
                if (btnLuu.Enabled)
                    btnLuu_Click(null, null);

            }
        }
        private void txtSoLuong_Enter(object sender, EventArgs e)
        {
            SpinEdit spinEdit1 = ((SpinEdit)sender);
            //spinEdit1.Invoke(
        }



        private void txtDonGia_Validated(object sender, EventArgs e)
        {

            txtTongTien.EditValue = Convert.ToDouble(txtSoLuong.EditValue) * Convert.ToDouble(txtDonGia.EditValue);

        }

        private void txtTongTien_Validated(object sender, EventArgs e)
        {
            txtDonGia.EditValue = Convert.ToDouble(txtTongTien.EditValue) / Convert.ToDouble(txtSoLuong.EditValue);

        }

        private void txtSoLuong_MouseUp(object sender, MouseEventArgs e)
        {
            SpinEdit spinEdit1 = ((SpinEdit)sender);
            spinEdit1.SelectAll();
        }


    }
}